package com.nidu.demo.oauth2.convertor;

import com.nidu.demo.auth.dto.AuthLoginCO;
import com.nidu.demo.base.BaseConvertor;
import com.nidu.demo.oauth2.dto.OAuth2AccessTokenCO;
import com.nidu.demo.oauth2.mapper.dataobject.OAuth2AccessTokenDO;
import com.nidu.demo.convertor.MapStructConfig;
import com.nidu.demo.oauth2.model.OAuth2AccessToken;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(config = MapStructConfig.class)
public interface OAuth2AccessTokenConvertor extends BaseConvertor<OAuth2AccessTokenDO, OAuth2AccessToken, OAuth2AccessTokenCO> {

    @Override
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    @Mapping(target = "createBy", ignore = true)
    @Mapping(target = "updateBy", ignore = true)
    OAuth2AccessTokenDO toDataObject(OAuth2AccessToken oAuth2AccessToken);

    /**
     * OAuth2AccessToken 转换为 AuthLoginCO
     *
     * @param token OAuth2访问令牌
     * @return 登录信息
     */
    @Mapping(source = "accessToken", target = "accessToken")
    @Mapping(source = "refreshToken", target = "refreshToken")
    @Mapping(source = "userId", target = "userId")
    @Mapping(source = "tenantId", target = "tenantId")
    @Mapping(source = "expiresTime", target = "expiresTime")
    AuthLoginCO toAuthLoginCO(OAuth2AccessToken token);
}